package me.numark.net;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import me.numark.utils.Settings;

/**
 * Created by tian on 14/10/20:下午11:35.
 */
public class AuthorizedJsonObjectRequest extends JsonObjectRequest {
    /**
     * Creates a new request.
     *  @param method        the HTTP method to use
     * @param url           URL to fetch the JSON from
     * @param params        A {@link org.json.JSONObject} to post with the request. Null is allowed
 *                      and
 *                      indicates no parameters will be posted along with request.
     * @param listener      Listener to receive the JSON response
     * @param errorListener Error listener, or null to ignore errors.
     */
    public AuthorizedJsonObjectRequest(int method, String url,
            Map<String, String> params,
            Response.Listener<JSONObject> listener,
            Response.ErrorListener errorListener) {
        super(method, url, null, listener, errorListener);
    }

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("uid", Settings.getUid());
        headers.put("token", Settings.getToken());
        return headers;
    }
}
